package com.tech.util;

import com.tech.repository.dto.GoodsInfo;
import com.tech.repository.entity.Goods;
import com.tech.repository.entity.GoodsImage;
import com.tech.repository.entity.Order;
import com.tech.repository.entity.User;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

/**
 * 存放一些模拟数据，用于测试
 */
public class TestDataUtil {
	public static final Logger LOG = LogProcessUtil.getLogger(TestDataUtil.class.getName());
	public static Integer userId = 1;
	public static String username = "艾希";
	public static String password = "123456";
	public static String email = "123456@qq.com";
	public static Integer goodsId = 1;
	public static String goodsName = "儿童玩具";
	public static int popularity = 0;
	public static String introduce = "小孩都喜欢";
	public static Integer sortId = 1;
	public static double price = 10;
	public static double secondPrice = 5;
	public static Goods.Condition condition = Goods.Condition.NEW;
	public static Goods.SendMode sendMode = Goods.SendMode.DELIVERY;
	public static int count = 1;
	public static Date createTime = new Date();
	public static Integer orderId = 1;
	public static Integer addressId = 1;
	public static Order.OrderState state = Order.OrderState.DELIVER;
	public static Integer goodsImageId = 1;
	public static String suffix = "png";

	public static BufferedImage IMAGE;
	public static BufferedImage ADDRESS_PAINTER_IMAGE;
	public static User USER;
	public static Goods GOODS;
	public static GoodsInfo GOODS_INFO_EMPTY_IMAG;
	public static Order ORDER;
	public static GoodsImage GOODS_IMAGE;
	public static GoodsInfo GOODS_INFO;

	static {
		try {
			IMAGE = ImageIO.read(TestDataUtil.class.getResourceAsStream("/images/port_background.png"));
			ADDRESS_PAINTER_IMAGE = ImageIO.read(TestDataUtil.class.getResourceAsStream("/images/address.png"));
			USER = new User(userId, username, password, null);
			GOODS = new Goods(goodsId, goodsName, popularity, introduce, price, secondPrice,
					userId, condition, sendMode, username, count, createTime);
			GOODS_INFO_EMPTY_IMAG = new GoodsInfo(GOODS, new ArrayList<>());
			ORDER = new Order(userId, goodsId, addressId, price, sendMode);
			GOODS_IMAGE = new GoodsImage(goodsImageId, goodsId, IMAGE, suffix,new Date().getTime());
			GOODS_INFO = new GoodsInfo(GOODS, new ArrayList<>(List.of(GOODS_IMAGE)));
		} catch (IOException e) {
			LOG.throwing(TestDataUtil.class.getName(), "static静态代码块", e);
		}
	}
}
